package boot.spring.config;

import boot.spring.mapper.UserAmountMapper;
import boot.spring.service.WebSocketServer;
import boot.spring.utils.CanalClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;


/**
 * WebScoket配置处理器
 */
@Configuration
public class WebSocketConfig {
    @Autowired
    WebSocketServer webSocketServer;
    @Autowired
    CloudStorageConfig cloudStorageConfig;
    @Autowired
    RedisTemplate redisTemplate;
	 /**
     * ServerEndpointExporter 作用
     *
     * 这个Bean会自动注册使用@ServerEndpoint注解声明的websocket endpoint
     *
     * @return
     */
	@Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Autowired
    private void setUserAmountMapper(UserAmountMapper userAmountMapper) {
        CanalClient.userAmountMapper = userAmountMapper;
    }

    @Autowired
    private void startGetUpdate() {
	    CanalClient.cloudStorageConfig = cloudStorageConfig;
	    CanalClient.webSocketServer = webSocketServer;
	    CanalClient.redisTemplate = redisTemplate;
        final CanalClient canalClient = new CanalClient();
        canalClient.start();
    }

}
